package bitCalculation;

public class MaximumProductOfWordLengths318 {
    public int maxProduct(String[] words) {
        int[] bits = new int[words.length];
        //预处理
        for (int i = 0; i < words.length; i++) {
            int temp = 0;
            String word = words[i];
            for (int j = 0; j < word.length(); j++) {
                temp = temp | (1 << (word.charAt(j) - 'a'));
            }

            bits[i] = temp;
        }

        int result = 0;
        for (int i = 0; i < words.length; i++) {
            for (int j = i + 1; j < words.length; j++) {
                if ((bits[i] & bits[j]) == 0) {
                    int len = words[i].length() * words[j].length();
                    result = Math.max(result,len);
                }
            }
        }

        return result;
    }
}
